package com.ptszyxx.popose.module.main.mine;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProviders;

import com.ptszyxx.popose.BR;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.databinding.FragmentMineExchangeRecordBinding;
import com.ptszyxx.popose.module.main.mine.adapter.MineExchangeRecordAdapter;
import com.ptszyxx.popose.module.main.mine.vm.MineExchangeRecordVM;
import com.ysg.base.BaseFragment;
import com.ysg.http.data.AppViewModelFactory;
import com.ysg.http.data.entity.exchange.ExchangeEntity;

import java.util.List;

/**
 * 兑换记录
 */
public class MineExchangeRecordFragment extends BaseFragment<FragmentMineExchangeRecordBinding, MineExchangeRecordVM> {
    private MineExchangeRecordAdapter adapter;

    public static MineExchangeRecordFragment getInstance() {
        return new MineExchangeRecordFragment();
    }

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_mine_exchange_record;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public MineExchangeRecordVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this, factory).get(MineExchangeRecordVM.class);
    }

    @Override
    public void initAdapter() {
        super.initAdapter();
        adapter = new MineExchangeRecordAdapter();
        binding.refreshView.initAdapterNoLine(adapter);
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.requestList(true);
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
        viewModel.uc.onRefreshEvent.observe(this, o -> binding.refreshView.setAdapterUI(adapter, (List<ExchangeEntity>) o, viewModel.isRefresh()));
    }



}
